package com.powernode.sqlinjection;

import com.powernode.commons.util.DbUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Author Arrebol
 * @Date 2024/8/1 23:34
 * @Project jdbc
 * @Description：
 * 使用PreparedStatement完成删除操作
 */
public class JdbcTestPreparedStatement3 {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            conn= DbUtils.getConnection();
            String deleteSql="delete from t_emp where id = ?";
            ps=conn.prepareStatement(deleteSql);
            ps.setShort(1,(short) 100);
            int count = ps.executeUpdate();
            System.out.println("执行的SQL语句为："+deleteSql);
            System.out.println("删除了条"+count+"记录");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DbUtils.close(null,ps,conn);
        }
    }
}
